package game.localization
{
	import engine.asset.*;
	import game.ui.core.*;
	
	public class RxLocalizationManager
	{
		private static var s_locales:Array = ["en_us", "te_st"];
		private static var s_currentLocale:String;
		private static var s_pendingLocale:String;
		private static var s_stringParams:Array = null;
		private static var s_paramIndex:int = 0;
		private static var s_callbacks:Vector.<Function> = new Vector.<Function>;
		
		public function RxLocalizationManager()
		{
		}
		
		public static function GetLocaleAssetLoader(param1:String = null) : RxAssetGroup
		{
			if (param1 == null)
			{
				param1 = s_currentLocale;
			}
			else
			{
				param1 = param1.toLowerCase();
			}
			if (!IsValidLocale(param1))
			{
				return null;
			}
			s_pendingLocale = param1;
			var _loc_2:* = "ui/fonts/fontlibrary-" + param1 + ".swf";
			var _loc_3:* = new RxAssetGroup();
			_loc_3.AddAsset(RxAssetSWF.Create(_loc_2, null));
			_loc_3.AddAsset(RxAssetCSV.Create("localization/strings-" + param1 + ".csv", null));
			_loc_3.AddAsset(RxAssetCSV.Create("fonts.csv", "fonts"));
			_loc_3.AddCallback(new RxAssetCallback(OnLocaleAssetsLoaded));
			return _loc_3;
		}
		
		private static function OnLocaleAssetsLoaded(param1:RxAssetCallback) : void
		{
			var _loc_2:RxAssetSWF = null;
			var _loc_3:RxAssetCSV = null;
			var _loc_4:RxAssetGroup = null;
			var _loc_5:Function = null;
			if (param1.m_result)
			{
				_loc_4 = param1.m_asset as RxAssetGroup;
				_loc_2 = RxAssetSWF.GetByName("fontswf");
				if (_loc_2)
				{
					_loc_2.GetClip().loaderInfo.loader.unloadAndStop(true);
					_loc_2.Delete();
				}
				_loc_3 = RxAssetCSV.GetByName("strings");
				if (_loc_3)
				{
					_loc_3.Delete();
				}
				_loc_2 = _loc_4.GetAsset(0) as RxAssetSWF;
				_loc_2.SetName("fontswf");
				_loc_3 = _loc_4.GetAsset(1) as RxAssetCSV;
				_loc_3.SetName("strings");
				s_currentLocale = s_pendingLocale;
				s_pendingLocale = null;
				RxFontLibrary.LoadFonts();
				RxUI.OnLocaleChanged();
				for each (_loc_5 in s_callbacks)
				{
					
					_loc_5();
				}
			}
		}
		
		public static function IsValidLocale(param1:String) : Boolean
		{
			return s_locales.indexOf(param1) != -1;
		}
		
		public static function GetLocale() : String
		{
			return s_currentLocale;
		}
	}
}